package com.woniuedu.search.controller;
import com.woniuedu.commonutils.R;
import com.woniuedu.search.entity.Search;
import com.woniuedu.search.serviec.ArticleService;
import com.woniuedu.search.serviec.CourseService;
import com.woniuedu.search.serviec.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Resource(name = "teacher")
    private TeacherService teacherService;

    @Resource(name = "article")
    private ArticleService articleService;

    @Resource(name = "course")
    private CourseService courseService;

    //查询所有
    @GetMapping("/all/{name}/{pagenum}/{size}")
    @ApiOperation("es 搜索引擎")
    public R all(@PathVariable(required = false) String name,
                 @PathVariable(required = false)Integer pagenum,
                 @PathVariable(required = false)Integer size){
        //分页对象
        Pageable pageable = PageRequest.of(pagenum, size);
        //查询
        Search search = new Search(teacherService.findByAll(name,pageable),
                articleService.findByAll(name,pageable),
                courseService.findByAll(name,pageable));
        return R.ok().data("search",search);
    }
//    @Resource
//    KillSender<Teacher> killSender;
//
//    @Autowired(required = false)
//    MessageMapper messageMapper;
//    //查询所有
//    @GetMapping("/mq")
//    public void send() {
//        killSender.send(
//                Teacher.builder()
//                .id("1213")
//                .build(),"direct_exchange", "amd","teacher");
//    }
}